var uname=document.getElementById("uname");
var upwd=document.getElementById("upwd");
function show1(){
  uname.nextElementSibling.style.display="block"
}
function test1(){
  var rrreg=/^[\u4E00-\u9FA5]{2,4}$/;
  if(rrreg.test(uname.value)){
    uname.nextElementSibling.style.display="none"
  }else{
    uname.nextElementSibling.style.color="red";
    uname.nextElementSibling.innerHTML="请正确填写用户名"
    return;
  }
}

function show2(){
  upwd.nextElementSibling.style.display="block"
}

function test2(){
    var rrreg=/^(\w){6,20}$/;
    if(rrreg.test(upwd.value)){
      upwd.nextElementSibling.style.display="none"
    }else{
      upwd.nextElementSibling.style.color="red";
      upwd.nextElementSibling.innerHTML="请输入正确格式密码"
    }
}

var haveRead=document.getElementById("haveRead")

  function login(){
    if(haveRead.checked==true){
      var uname=document.getElementById("uname").value;
      var upwd=document.getElementById("upwd").value; 
      console.log(uname,upwd)
      if(! /^[\u4E00-\u9FA5]{2,4}$/.test(uname) || !/^(\w){6,20}$/.test(upwd)){
        alert("请正确填写用户信息");
        return;
      }
      var formdata="uname="+uname+"&upwd="+upwd;
      console.log(formdata)
      ajax({
        url:"/user/login",
        type:"post",
        data:formdata,
        dataType:"json" 
      })            
      .then(function(result){
          console.log(result);
          if(result.code==200){
            alert("登录成功")
            window.location.href="/"
            //window.href(url),重定向
          }else{
            alert('用户名或者密码错误！！')
          }
      })
    }else{ 
      alert("请先阅读用户登录协议")
    }
}